#!/usr/bin/env python
#coding:gbk

import texttable as ttb

charmap = [
[ "<NUL>",    "Null char."],
[ "<SOH>",    "Start of Header"],
[ "<STX>",    "Start of Text"],
[ "<ETX>",    "End of Text"],
[ "<EOT>",    "End of Transmission"],
[ "<ENQ>",    "Enquiry"],
[ "<ACK>",    "Acknowledgment"],
[ "<BEL>",    "Bell"],
[ "<BS>",    "Backspace"],
[ "<HT>",    "Horizontal Tab"],
[ "<LF>",    "Line Feed"],
[ "<VT>",    "Vertical Tab"],
[ "<FF>",    "Form Feed"],
[ "<CR>",    "Carriage Return"],
[ "<SO>",    "Shift Out"],
[ "<SI>",    "Shift In"],
[ "<DLE>",    "Data Link Escape"],
[ "<DC1/XON>",    " Device Control 1"],
[ "<DC2>",    "Device Control 2"],
[ "<DC3/XOFF>",    "Device Control 3"],
[ "<DC4>",    "Device Control 4"],
[ "<NAK>",    "Negative Acknowledgement"],
[ "<SYN>",    "Synchronous Idle"],
[ "<ETB>",    "End of Trans. Block"],
[ "<CAN>",    "Cancel"],
[ "<EM>",    "End of Medium"],
[ "<SUB>",    "Substitute"],
[ "<ESC>",    "Escape"],
[ "<FS>",    "File Separator"],
[ "<GS>",    "Group Separator"],
[ "<RS>",    "Request to SendRecord Separator"],
[ "<US>",    "Unit Separator"],
[ "<SP>",    "Space"],
[ "!",    "exclamation mark"],
[ "\"",    "double quote"],
[ "#",    "number sign"],
[ "$",    "dollar sign"],
[ "%",    "percent"],
[ "&",    "ampersand"],
[ "'",    "single quote"],
[ "(",    "left/opening parenthesis"],
[ ")",    "right/closing parenthesis"],
[ "*",    "asterisk"],
[ "+",    "plus"],
[ ",",    "comma"],
[ "-",    "minus or dash"],
[ ".",    "dot"],
[ "/",    "forward slash"],
[ "0"],
[ "1"],
[ "2"],
[ "3"],
[ "4"],
[ "5"],
[ "6"],
[ "7"],
[ "8"],
[ "9"],
[ ":",    "colon"],
[ ";",    "semi-colon"],
[ "<",    "less than"],
[ "=",    "equal sign"],
[ ">",    "greater than"],
[ "?",    "question mark"],
[ "@",    "AT symbol"],
[ "A"],
[ "B"],
[ "C"],
[ "D"],
[ "E"],
[ "F"],
[ "G"],
[ "H"],
[ "I"],
[ "J"],
[ "K"],
[ "L"],
[ "M"],
[ "N"],
[ "O"],
[ "P"],
[ "Q"],
[ "R"],
[ "S"],
[ "T"],
[ "U"],
[ "V"],
[ "W"],
[ "X"],
[ "Y"],
[ "Z"],
[ "[",    "left/opening bracket"],
[ "\\",    "back slash"],
[ "]",    "right/closing bracket"],
[ "^",    "caret/circumflex"],
[ "_",    "underscore"],
[ "`"],
[ "a"],
[ "b"],
[ "c"],
[ "d"],
[ "e"],
[ "f"],
[ "g"],
[ "h"],
[ "i"],
[ "j"],
[ "k"],
[ "l"],
[ "m"],
[ "n"],
[ "o"],
[ "p"],
[ "q"],
[ "r"],
[ "s"],
[ "t"],
[ "u"],
[ "v"],
[ "w"],
[ "x"],
[ "y"],
[ "z"],
[ "{",    "left/opening brace"],
[ "|",    "vertical bar"],
[ "}",    "right/closing brace"],
[ "~",    "tilde"],
[ "<DEL>",    "delete"],
]

def main():
    table = ttb.Texttable()
    table.header(["CHAR", "DEC", "HEX", "BIN", "DESCRIPTION"])
    table.set_cols_align(["c", "r", "r", "r", "l"])
    for i in xrange(len(charmap)):
        char = charmap[i][0]
        dec = i
        hex = '0x' + format(i, "02X")
        bin = 'b ' + format(i, "08b")
        des = charmap[i][1] if len(charmap[i]) > 1 else ""
        table.add_row([char, dec, hex, bin, des])
    print table.draw()

if __name__ == '__main__':
    main()
